<?php
	session_start();
	require 'include/configDB.php';
	$guru = mysql_query("SELECT * FROM nilai");

	if (! isset($_SESSION['role']) || ($_SESSION['role'] != "Admin") && ($_SESSION['role'] != "Siswa")) {
  		header('Location: login.php');
	}
	$id_pengguna = $_SESSION['id_pengguna'];
	$query_siswa = mysql_query("SELECT * FROM siswa WHERE NIS='$id_pengguna'");
	$data = mysql_fetch_assoc($query_siswa);

	$id_kelas = $data['id_kelas'];
	$query_kelas = mysql_query("SELECT * FROM kelas WHERE id='$id_kelas'");
	$kelas_data = mysql_fetch_assoc($query_kelas);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Laporan Nilai Siswa</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="clockp.js"></script>
<script type="text/javascript" src="clockh.js"></script> 
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="ddaccordion.js"></script>
<script type="text/javascript">
ddaccordion.init({
	headerclass: "submenuheader", //Shared CSS class name of headers group
	contentclass: "submenu", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["suffix", "<img src='images/plus.gif' class='statusicon' />", "<img src='images/minus.gif' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})
</script>

<script type="text/javascript" src="jconfirmaction.jquery.js"></script>
<script type="text/javascript">
	
	$(document).ready(function() {
		$('.ask').jConfirmAction();
	});
	
</script>

<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="niceforms-default.css" />
<style>
	<?php include 'include_style.php'; ?>
</style>
</head>
<body>
<div id="main_container">

	<?php include 'header.php'; ?>
    
    <div class="main_content">
                
                    
    <div class="center_content">  
		
    
	
    <div class="left_content">
    
    		<?php include 'left_content.php'; ?>
    		<?php include 'calendar.php' ; ?>
    		
    </div>  
    
    <div class="right_content">
	<h2>Data Nilai Akademik</h2>
	<form method="post" action="laporan_data_nilaiSiswa.php">
		<table>
			<tr>
				<td>
					Kelas
				</td>
				<td>:</td>
				<td>
					<select name="tingkat" id="tingkat">
						<option value="">---------Pilih----------</option>

						<option value="10" <?php if (isset($_POST['tingkat']) && ($_POST['tingkat'] == "10")) echo "selected";?>>10</option>
						<option value="11" <?php if (isset($_POST['tingkat']) && ($_POST['tingkat'] == "11")) echo "selected";?>>11</option>
						<option value="12" <?php if (isset($_POST['tingkat']) && ($_POST['tingkat'] == "12")) echo "selected";?>>12</option>

					</select>
				</td>
			</tr>
			<?php
				$query = mysql_query("SELECT * FROM tahun_ajaran");
			?>
			<tr>
				<td>
					Tahun Ajaran
				</td>
				<td>
					:
				</td>
				<td>
					<select name = "tahun_ajaran" id="tahun_ajaran">
						<option value="NULL">---------Pilih----------</option>
						<?php

						while ($tahun_ajaran_data = mysql_fetch_assoc($query)) {
						?>
						<option value="<?php echo $tahun_ajaran_data['id'];?>" <?php if (isset($_POST['tahun_ajaran']) && ($_POST['tahun_ajaran'] == $tahun_ajaran_data['id'])) echo "selected";?>>
							<?php echo $tahun_ajaran_data['tahun_ajaran'];?>
						</option>
						<?php } ?>	
					</select>
				</td>
			</tr>
			<tr>	
				<td>
					Semester
				</td>
				<td>:</td>
				<td>
					<select name="semester" id="semester">
						<option value="">---------Pilih----------</option>
						<option value="Genap" <?php if (isset($_POST['semester']) && ($_POST['semester'] == "Genap")) echo "selected";?>>Genap</option>
						<option value="Ganjil" <?php if (isset($_POST['semester']) && ($_POST['semester'] == "Ganjil")) echo "selected";?>>Ganjil</option>
					</select>
				</td>
			</tr> 
			<tr>	
				<td>
					Nama Mata Pelajaran 
				</td>
				<td>:</td>
				<td>
					<select name= "matpel" id="matpel">
						<option value="NULL">---------Pilih----------</option>
						<?php
							$matpel_query = mysql_query("SELECT * FROM mata_pelajaran");
							while ($matpel_data = mysql_fetch_assoc($matpel_query)) 
							{
								// $id_penugasan=$jadpel_data['id_penugasan'];
								// $penugasan_query = mysql_query("SELECT * FROM penugasan_guru WHERE id='$id_penugasan' ");
								// $penugasan_data = mysql_fetch_assoc($penugasan_query);
								// $id_matpel = $penugasan_data['id_matpel'];
								// $matpel_data = mysql_fetch_assoc(mysql_query("SELECT * FROM mata_pelajaran WHERE id='$id_matpel'"));
						?>
							<option value="<?php echo $matpel_data['id']?>" <?php if (isset($_POST['matpel']) && ($_POST['matpel'] == $matpel_data['id'])) echo "selected";?>><?php echo $matpel_data['nama']?></option>
						<?php 
							}
						?>
					</select>
				</td>
			</tr>
			<tr>
				<td>
					<input type="submit" name="submit" class="menuitem_red"value="Lihat"/>
				</td>	
			</tr>
		</table>
		</form>
		<form method="post">
			<?php
				if(isset($_POST['tingkat']) && isset($_POST['matpel']) && isset($_POST['semester']) && isset($_POST['tahun_ajaran'])){
							$tingkat = $_POST['tingkat'];
							// echo $tingkat;
							$matpel = $_POST['matpel'];
							// echo "$matpel";
							$semester = $_POST['semester'];
							// echo "$semester";
							$id_jurusan = $kelas_data['id_jurusan'];
							$no_kelas = $kelas_data['nomor'];
							$tahun_ajaran = $_POST['tahun_ajaran'];
							$query_kelas = mysql_query("SELECT * FROM kelas WHERE tingkat='$tingkat' AND id_jurusan='$id_jurusan' AND nomor='$no_kelas'");
							$kelas_data = mysql_fetch_assoc($query_kelas);
							$id_kelas = $kelas_data['id'];
							//echo "$id_kelas";
							$query_nilai = mysql_query("SELECT * FROM nilai WHERE id_kelas='$id_kelas' AND id_matpel='$matpel' AND semester='$semester' AND id_tahun_ajaran='$tahun_ajaran' AND id_siswa='$id_pengguna'");
						}
			?>
		</br>
		<table id="rounded-corner" summary="2007 Major IT Companies' Profit">
			<thead>
				<tr>
			
					<th scope="col" class="rounded">No</th>
					<th scope="col" class="rounded">Tipe Nilai</th>
					<th scope="col" class="rounded">Nilai</th>
					<th scope="col" class="rounded">Keterangan</th>
				</tr>
			</thead>
				
			<tbody>
				<?php
					if(isset($_POST['tingkat']) && isset($_POST['matpel']) && isset($_POST['semester']) && isset($_POST['tahun_ajaran'])){
						$i = 1;
						// $counter_ulangan = 0;
						// $counter_tugas = 0;
						// $counter_ujian = 0;
						while($nilai_data = mysql_fetch_assoc($query_nilai))
						{
							// $id_siswa = $nilai_data['id_siswa'];
							// $query_siswa = mysql_query("SELECT * FROM siswa WHERE NIS='$id_siswa'");
							// $siswa_data = mysql_fetch_assoc($query_siswa);
							// $id_matpel = $nilai_data['id_matpel'];
							// $nilai_akhir = $nilai_data['nilai'];
							// $matpel_query = mysql_query("SELECT * FROM mata_pelajaran WHERE id='$id_matpel'");
							// $data_matpel = mysql_fetch_assoc($matpel_query);
							// $kkm = $data_matpel['kkm'];
							// if ($nilai_akhir >= $kkm) {
							// 	$hasil = "KKM tercapai";
							// }else{
							// 	$hasil = "KKM tidak tercapai"; 
							// }
						 echo 
						 '
						 	<tr>
						 		<td>'.$i.'</td>
								<td>'.$nilai_data['tipe_nilai'].'</td>
								<td>'.$nilai_data['nilai'].'</td>
								<td>'.$nilai_data['tipe_nilai'].' '.$nilai_data['keterangan'].'</td>
							</tr>
						 
						 ';
						 $i++;
					}
				}	
				?>
				
				
				
			</tbody>
		</table>
		

    </div><!-- end of right content-->
            
                    
  </div>   <!--end of center content -->               
                    
    <div class="clear"></div>
    </div> <!--end of main content-->
	
    
    <div class="footer">
        	<?php include 'footer.php'; ?>

    	
    </div>

</div>	
</form>	
</body>
</html>